import Vue from 'vue'
import Vuex from 'vuex'
Vue.use(Vuex);

export default new Vuex.Store({

  state:{
    User:{
      //存储token
      Authorization:localStorage.getItem('Authorization') ? localStorage.getItem('Authorization') : '',
      //用户ip地址
      Ip:localStorage.getItem('Ip') ? localStorage.getItem('Ip') : '',
      //用户城市地址
      CityName:localStorage.getItem('CityName') ? localStorage.getItem('CityName') : '',
      //用户是否登陆
      isLogin:localStorage.getItem('Authorization') ? true : false,
    },
    UserInfo:JSON.parse(localStorage.getItem("UserInfo")) ? JSON.parse(localStorage.getItem("UserInfo")) : '',
  },
  mutations:{
    //修改token,并将token存入localStorage
    LoginChangeToken(state,token){
      state.User.Authorization=token;
      localStorage.setItem("Authorization",token);
    },
    AddUserCenterInfo(state,UserInfo){
      state.UserInfo = JSON.stringify(UserInfo)
      localStorage.setItem("UserInfo",JSON.stringify(UserInfo))
      return true
    },
  },
  actions:{},
})
